package com.duyus.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter { // 这是javaweb的三大组件之一 要想使用 必须 添加注解

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {  // 只调用一次
        Filter.super.init(filterConfig);
        System.out.println("Init 初始化方法执行了");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到了请求。。。。放行前的逻辑");
        filterChain.doFilter(servletRequest,servletResponse);  // 放行请求
        System.out.println("拦截到了请求。。。。放行后的逻辑");
    }

    @Override
    public void destroy() {  // 只调用一次
        Filter.super.destroy();
        System.out.println("destory销毁了方法");
    }
}
